



import string
from typing import List, Tuple
import torch
from word_vec_encoders.mini_sequence_conv_encoder import MiniSequenceConvEncoder
from word_vec_encoders.word_vec_encoder_base import WordVecEncoderBase
from utils.handian_data import HandianData


class WubiWordVecEncoder(MiniSequenceConvEncoder):

    def __init__(self, embedding_dim = 32) -> None:
        '五笔所用符号，包括a-z的字母，以及空格'
        symbols = [' '] + [c for c in string.ascii_lowercase]
        super().__init__(name = 'wubi', miniseq_symbols = symbols, fixed_miniseq_len = 4, embedding_dim = embedding_dim)

    def sentence_to_miniseqs_cached(self, sentence:str) -> list:
        if sentence in self._sentence_miniseq_cache:
            return self._sentence_miniseq_cache[sentence]
        sentence_miniseqs = []
        for char in sentence:
            miniseq = HandianData.get_wubi_seq_cached(char)
            miniseq = miniseq.lower()
            sentence_miniseqs.append(miniseq)
        self._sentence_miniseq_cache[sentence] = sentence_miniseqs
        return sentence_miniseqs